efi: Lock down the kernel if booted in secure boot mode
authorDavid Howells <dhowells@redhat.com>
Wed, 5 Apr 2017 16:40:29 +0000 (17:40 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 14 Jan 2018 19:45:05 +0000 (19:45 +0000)
UEFI Secure Boot provides a mechanism for ensuring that the firmware will
only load signed bootloaders and kernels.  Certain use cases may also
require that all kernel modules also be signed.  Add a configuration option
that to lock down the kernel - which includes requiring validly signed
modules - if the kernel is secure-booted.

Signed-off-by: David Howells <dhowells@redhat.com>
Gbp-Pq: Topic features/all/lockdown
Gbp-Pq: Name 0040-efi-Lock-down-the-kernel-if-booted-in-secure-boot-mo.patch

arch/x86/Kconfig
arch/x86/kernel/setup.c

index a09ccab348fcad3004d9c1641b2a1b03ba737ad8..6bc8db6985f41f672f48c2f84c3c2f712f2710dd 100644 (file)
@@ -1887,6 +1887,18 @@ config EFI_MIXED
 
           If unsure, say N.
 
+config EFI_SECURE_BOOT_LOCK_DOWN
+       def_bool n
+       depends on EFI
+       prompt "Lock down the kernel when UEFI Secure Boot is enabled"
+       ---help---
+         UEFI Secure Boot provides a mechanism for ensuring that the firmware
+         will only load signed bootloaders and kernels.  Certain use cases may
+         also require that all kernel modules also be signed and that
+         userspace is prevented from directly changing the running kernel
+         image.  Say Y here to automatically lock down the kernel when a
+         system boots with UEFI Secure Boot enabled.
+
 config SECCOMP
        def_bool y
        prompt "Enable seccomp to safely compute untrusted bytecode"
index b3f8350b34f4696fcd081ee625e497779a5a22f5..e6a2155651cea8146fca98f1072008f350ff68e0 100644 (file)
@@ -70,6 +70,7 @@
 #include <linux/tboot.h>
 #include <linux/jiffies.h>
 #include <linux/mem_encrypt.h>
+#include <linux/security.h>
 
 #include <linux/usb/xhci-dbgp.h>
 #include <video/edid.h>
@@ -1204,7 +1205,12 @@ void __init setup_arch(char **cmdline_p)
                        break;
                case efi_secureboot_mode_enabled:
                        set_bit(EFI_SECURE_BOOT, &efi.flags);
-                       pr_info("Secure boot enabled\n");
+                       if (IS_ENABLED(CONFIG_EFI_SECURE_BOOT_LOCK_DOWN)) {
+                               lock_kernel_down();
+                               pr_info("Secure boot enabled and kernel locked down\n");
+                       } else {
+                               pr_info("Secure boot enabled\n");
+                       }
                        break;
                default:
                        pr_info("Secure boot could not be determined\n");